package com.wwtech.epp.view.dynamicapp;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.socks.library.KLog;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.DynamicUI;

/**
 * Created by hu on 2017/9/18.
 * 单行输入框
 */

public class TextAppView extends LinearLayout{

    private TextView name;
    private EditText content;
    private DynamicUI.DataBean dataBean;
    private String key;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public DynamicUI.DataBean getDataBean() {
        return dataBean;
    }

    public void setDataBean(DynamicUI.DataBean dataBean) {
        this.dataBean = dataBean;
        initContent();
    }

    public boolean isValidate() {
        return validate;
    }

    public void setValidate(boolean validate) {
        this.validate = validate;
    }

    private boolean validate;

    public TextView getName() {
        return name;
    }

    public void setName(TextView name) {
        this.name = name;
    }

    public EditText getContent() {
        return content;
    }

    public void setContent(EditText content) {
        this.content = content;
    }

    public TextAppView(Context context) {
        super(context);
        init(context);
    }

    public TextAppView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TextAppView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.appview_text, this, true);
        name = (TextView) view.findViewById(R.id.name);
        content = (EditText) view.findViewById(R.id.content);
    }

    private void initContent() {
        content.setHint(dataBean.getPlacehold());
        KLog.i(dataBean.getTitle().length());
        String empty = "";
        if (dataBean.getTitle().length() < 5) {
            for (int i = 0; i < (5 - dataBean.getTitle().length())*4; i++) {
                empty += " ";
            }
        }
        name.setText(dataBean.getTitle() + empty);
    }
}
